package skills;

import loadsave.Memento;
import loadsave.loadsaveobject.Iterator;
import loadsave.loadsaveobject.LoadSaveObject;
import loadsave.loadsaveobject.LoadSaveObjectComposite;
import scheduler.DuplicateEventException;
import entity.Entity;
import handlers.DetectTrapHandler;

/**
 * The purpose of DetectTrapSkill is to provide a concrete
 * subtype of Skill.
 * 
 * The Skill class is responsible for implementing the
 * interface for execute(), which is responsible for
 * creating an interaction handler.
 * 
 * @author DangMH
 *
 */
public class DetectTrapSkill extends Skill {
	
	public DetectTrapSkill(String modelName) {
		super(modelName);
	}
	public DetectTrapSkill() { }
	/**
	 * Responsible for creating an interaction handler.
	 * @throws DuplicateEventException 
	 */
	public void execute( Entity e ) {
		( new DetectTrapHandler(e) ).detectTraps(getLevel());
	}

	public Memento getMemento() {
		return new Memento() {

			public LoadSaveObject getState() {
				LoadSaveObjectComposite ret = new LoadSaveObjectComposite( "", "DetectTrapSkill" );
				Iterator<LoadSaveObject> iter = DetectTrapSkill.super.getMemento().getState().getIterator();
				for( iter.init(); iter.hasNext(); iter.next() ) {
					ret.add( iter.getCurrKey().getValue(), iter.getCurrVal() );
				}
				
				return ret;
			}

			public void restoreState(LoadSaveObject lso) {
				DetectTrapSkill.super.getMemento().restoreState( lso );
			}
		};
	}

	public DetectTrapSkill clone() {
		return new DetectTrapSkill(getName());
	}

}
